import http.*
import korlibs.korge.scene.*
import korlibs.korge.service.storage.*
import korlibs.korge.view.*
import korlibs.render.*

class ConfigScene : Scene() {
    override suspend fun SContainer.sceneMain() {
        val storage = views.storage
        while (storage.getOrNull("serverIp") == null) {
            connect()
        }
        sceneContainer.changeTo { LoginScene() }
    }

    private suspend fun connect() {
        val address = views.gameWindow.prompt("Укажите IP-арес сервера")
        if (PointsHttpClient(address, "").houses()) {
            storage["serverIp"] = address
        } else {
            views.gameWindow.alert("Can't connect to server")
        }
    }
}
